package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.BeautifyBean;
import com.project.mapper.IBeautifyMapper;
import com.project.service.IBeautifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class BeautifyServiceImp implements IBeautifyService {
    @Autowired
    private IBeautifyMapper beautifyMapper;
    @Override
    public Boolean updateBeautifulProductStatus(String productNum,String status, String reason) {
        QueryWrapper<BeautifyBean> qw=new QueryWrapper<>();
        qw.eq("productNum",productNum);
        BeautifyBean bean = beautifyMapper.selectOne(qw);
        if (bean != null && bean.getStatus().equals("未审核")) {
            bean.setStatus(status);
            bean.setReason(reason);
            beautifyMapper.updateById(bean);
            return true;
        }

        return false;
    }

    @Override
    public IPage<BeautifyBean> findByItem(int pageNO,String status) {
        QueryWrapper<BeautifyBean> qw = new QueryWrapper<>();
        if (!status.equals("")&& status !=null){

            qw.eq("status",status);
        }
        return beautifyMapper.selectPage(new Page<>(pageNO,3),qw);
    }
}
